// @ 516
// _(:з」∠)_

define([ "layDate" ], function( laydate ) {
    'use strict';

    let disEventPanel = {
        disPanel: null,
        disFilter: null,
        disBasicData: null,
        disSensitive: null,
        disListBox: null,
        eventIndex: 0,
        disListData: null,
        disCondition: {},
        initView: function() {
            let _this = this;

            _this.disPanel = document.querySelector(".leftMain_cont .disaster .item_cont");
            _this.initFilter();
            _this.initBasicData();
            _this.initSensitive({ type: "init" });
            _this.initDisList({ type: "init" });
        },
        initFilter: function() {
            let _this = this,
                thisView = `<div class="filter">
                                        <div class="disAndType">
                                            <div class="selectElmt areaSelect">
                                                <h>地区</h>
                                                <div name="select" class="area">
                                                    <h></h> <ul></ul>
                                                </div>
                                            </div>
                                            <div class="selectElmt cropSelect">
                                                <h>作物</h>
                                                <div name="select" class="crop">
                                                    <h></h> <ul></ul>
                                                </div>
                                            </div>
                                            <div class="disTypeList">
                                                <h>灾种</h>
                                                <ul></ul>
                                            </div>
                                        </div>
                                        <div class="timeAndKey">
                                            <div class="selectElmt growthSeason">
                                                <h>生长季</h>
                                                <div name="select" class="gseason">
                                                    <h></h> <ul></ul>
                                                </div>
                                            </div>
                                            <div class="keyword">
                                                <input type="text" name="keyword" value="" placeholder="请输入关键字" class="hidden" />
                                                <i class="fa fa-search" aria-hidden="true" title="关键字搜索"></i>
                                            </div>
                                            <span class="bd_cg" title="气象资料"></span>
                                        </div>
                                    </div>`;

            _this.disPanel.insertAdjacentHTML("beforeEnd", thisView);
            _this.disFilter = _this.disPanel.querySelector(".filter");

            // 初始化select
            _this.initSelect();

            // 初始化关键字
            let search_ = _this.disFilter.querySelector(".keyword i.fa");
            search_.addEventListener( 'click', function(e) {
                let prevElmt = e.target.previousElementSibling;
                if ( prevElmt.hasClass("hidden") ) {
                    prevElmt.removeClass("hidden");
                } else {
                    prevElmt.addClass("hidden");
                }
            }, false);

            // 初始化气象资料
            let bd_cg = _this.disFilter.querySelector(".bd_cg");
            bd_cg.addEventListener( 'click', function(e) {
                let elmt = _this.disPanel.querySelector(".basic_data");
                if ( elmt.hasClass("show") ) {
                    elmt.hide();
                    elmt.removeClass("show");
                } else {
                    elmt.addClass("show");
                    elmt.show();
                }
            }, false);
        },
        initSelect: function() {
            let _this = this,
                currentUrl = _this.disEventPath({ urlTypes: "condition" });

            RST.basic( currentUrl, "", function( result ) {
                let ctYear = new Date().getFullYear(), customData = [],
                    area_select = _this.disFilter.querySelector("div[name='select'].area"),
                    crop_select = _this.disFilter.querySelector("div[name='select'].crop"),
                    disType_list = _this.disFilter.querySelector(".disTypeList ul"),
                    gseason_select = _this.disFilter.querySelector("div[name='select'].gseason");

                // 初始化为冬小麦生育季
                for ( let x = (ctYear - 1); x >= 2014; x-- ) {
                    customData.push({ "id": x, "name": x+'~'+(x+1)+'生长季', "value": x+'~'+(x+1) });
                }

                // 初始化select
                Elmt.select({ elmt: area_select, data: result.data.area });
                Elmt.select({ elmt: crop_select, data: result.data.crop });
                Elmt.select({ elmt: gseason_select, data: customData });
                customData = null;

                // 初始化 地区 - 作物 - 灾种 关联
                // 地区 => 作物
                _this.listenerSelect({
                    elmt: area_select.querySelector("h"),
                    callBack: function( e ) {
                        let newData = [],
                            pValue = e.target.getAttribute("value");

                        // 关联作物
                        for ( let x = 0; x < result.data.crop.length; x++ ) {
                            if ( result.data.crop[x].pName == pValue ) {
                                newData.push( result.data.crop[x] );
                            }
                        }

                        Elmt.select({ elmt: crop_select, data: newData, type: "reset" });
                        newData = null;
                        _this.triggerSearch({ type: "" });
                    }
                });

                // 作物 => 灾种
                _this.listenerSelect({
                    elmt: crop_select.querySelector("h"),
                    callBack: function( e ) {
                        let itemView = ``,
                            pValue = e.target.getAttribute("value");

                        // 关联灾种
                        for ( let x = 0; x < result.data.disaster.length; x++ ) {
                            if ( result.data.disaster[x].pName == pValue ) {
                                itemView += `<li value="${ result.data.disaster[x].value }">
                                                        ${ result.data.disaster[x].name }
                                                        <div class="round">
                                                            <div class="circle">0</div>
                                                            <div class="circle_bottom animation"></div>
                                                            <div class="circle_bottom2 animation2"></div>
                                                        </div>
                                                    </li>`;
                            }
                        }

                        disType_list.textContent = "";
                        disType_list.insertAdjacentHTML("beforeEnd", itemView);

                        // 关联生育季
                        let newDatas = [];
                        if ( pValue != "Winter wheat" ) {
                            for ( let x = (ctYear - 1); x >= 2014; x-- ) {
                                newDatas.push({ "id": x, "name": (x+1)+'生长季', "value": (x+1) });
                            }
                        } else {
                            for ( let x = (ctYear - 1); x >= 2014; x-- ) {
                                newDatas.push({ "id": x, "name": x+'~'+(x+1)+'生长季', "value": x+'~'+(x+1) });
                            }
                        }

                        Elmt.select({ elmt: gseason_select, data: newDatas, type: "reset" });

                        // 更新敏感期
                        let area = area_select.querySelector("h").getAttribute("value");

                        _this.sensitiveView({
                            type: "search",
                            area: area,
                            crop: pValue
                        });

                        setTimeout(function() {
                            _this.triggerSearch({ type: "" });
                        }, 210);
                    }
                });

                // 生育季
                _this.listenerSelect({
                    elmt: gseason_select.querySelector("h"),
                    callBack: function( e ) {
                        // 更新敏感期
                        let area = area_select.querySelector("h").getAttribute("value"),
                            crop = crop_select.querySelector("h").getAttribute("value");

                        _this.sensitiveView({
                            type: "search",
                            area: area,
                            crop: crop
                        });

                        setTimeout(function() {
                            _this.triggerSearch({ type: "" });
                        }, 210);
                    }
                });

                // 默认选择 黄淮海 + 冬小麦
                area_select.querySelector("li[value='HHH']").click();
                crop_select.querySelector("li[value='Winter wheat']").click();
            });
        },
        listenerSelect: function( param ) {
            let _this = this;

            let observer = new MutationObserver( function( mutations ) {
                mutations.forEach(function( mutation ) {
                    if ( mutation.type == "attributes" ) {
                        param.callBack( mutation );
                    }
                });
            });
            
            observer.observe( param.elmt, { attributes: true });
        },
        checkCondition: function() {
            let _this = this,
                keyWord  = _this.disFilter.querySelector("input[name='keyword']").value,
                area = _this.disFilter.querySelector("div[name='select'].area h").getAttribute("value"),
                crop = _this.disFilter.querySelector("div[name='select'].crop h").getAttribute("value");
        
            // 对时间做初始化判断
            let time = _this.disFilter.querySelector("div[name='select'].gseason h").getAttribute("value"),
                growthList = _this.disSensitive.querySelectorAll(".sp_growth li"),
                starTime = null, endTime = null;

            if ( time.indexOf("~") > -1 && growthList.length > 0 ) {
                starTime = growthList[0].getAttribute("title").split("~")[0];
                endTime  = growthList[growthList.length-1].getAttribute("title").split("~")[1];
            } else if ( time.indexOf("~") < 0 && growthList.length > 0 ) {
                starTime = growthList[0].getAttribute("title").split("~")[0];
                endTime  = growthList[growthList.length-1].getAttribute("title").split("~")[1];
            } else if ( time.indexOf("~") > -1 && growthList.length == 0 ) {
                starTime = formatTime( new Date( time.split("~")[0]+'-07-01' ), 'day' );
                endTime  = formatTime( new Date( time.split("~")[1]+'-07-01' ), 'day' );
            } else if ( time.indexOf("~") < 0 && growthList.length == 0 ) {
                starTime = formatTime( new Date( time+'-01-01' ), 'day' );
                endTime  = formatTime( new Date( time+'-12-31' ), 'day' );
            }
                

            let result = { ok: true, msg: "", param: {} };

            // 时间范围
            if ( starTime != "" && endTime != "" ) {
                result.param["starTime"] = starTime;
                result.param["endTime"] = endTime;
            } else {
                result.ok = false;
                result.msg = "请选择时间范围";
            }

            // 关键字或者条件
            if ( keyWord != "" ) {
                result.param["keyWord"] = keyWord;
            } else {
                result.param["area"] = area || "";
                result.param["crop"] = crop || "";
                result.param["disaster"] = "";
            }

            return result;
        },
        triggerSearch: function( param ) {
            let _this = this;

            _this.disCondition = _this.checkCondition();

            if ( !_this.disCondition.ok ) {
                Popup.tipPopup({ type: "toast", content: _this.disCondition.msg });
                return false;
            }
    
            let url = _this.disEventPath({ urlTypes: "search" }), urlParam = "";

            if ( param ) {
                if ( param && param.type == "sensitive" ) {
                    _this.disCondition.param.starTime = param.startTime;
                    _this.disCondition.param.endTime = param.endTime;
                }
            }

            // 重置清空事件高级选项
            document.querySelector(".disEvent_setting").hide();
            document.querySelector(".disEvent_setting").textContent = "";

            urlParam += "disasterArea="+ _this.disCondition.param.area
                    +"&cropName="+ _this.disCondition.param.crop
                    +"&disasterType="+ _this.disCondition.param.disaster
                    +"&startDate="+ _this.disCondition.param.starTime
                    +"&endDate="+ _this.disCondition.param.endTime;
            

            RST.basic( url + urlParam, "", function( result ) {
                // 更新灾害列表
                _this.disListData = result;
                _this.initDisList({ type: "search" });

                // 更新灾种状态
                let disList = _this.disFilter.querySelectorAll(".disTypeList li");

                // 清空所有状态
                for ( let x = 0; x < disList.length; x++ ) {
                    let disItem = disList[x].querySelector(".circle");
                    disItem.textContent = 0;
                    disItem.parentNode.removeClass("occur");
                }

                if ( result.status == 1 ) {
                    let num = 0;
                    for ( let x = 0; x < disList.length; x++ ) {
                        for ( let y = 0; y < result.data.length; y++ ) {
                            if ( result.data[y].disasterType == disList[x].getAttribute("value") ) {
                                let disItem = disList[x].querySelector(".circle");
                                disItem.textContent = num = num + 1;
                                if ( result.data[y].disasterStatus == 0 ) {
                                    disItem.parentNode.removeClass("occur").addClass("occur");
                                }
                            } else {
                                num = 0;
                            }
                        }
                    }
                }
            });
        },
        initBasicData: function( param ) {
            let _this = this,
                thisView = `<div class="basic_data rightPop">
                                    <div class="bd_head">农业气象基本资料</div>
                                    <div class="bd_main">
                                        <ul class="bd_list">
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>作物分布</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>生育期分布</span> </li>
                                            <li class="bd_item bd_item_3"> <input type="radio" name="bd_" value="" /> <span>小气候站分布</span> </li>
                                            <li class="bd_item bd_item_2 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>灾害风险区划</span> </li>
                                            <li class="bd_item bd_item_2"> <input type="radio" name="bd_" value="" /> <span>历史灾害图谱</span> </li>
                                            <li class="bd_item bd_item_2 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>土地利用数据</span> </li>
                                            <li class="bd_item bd_item_2"> <input type="radio" name="bd_" value="" /> <span>土壤情况数据</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>积温</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>有效积温</span> </li>
                                            <li class="bd_item bd_item_3"> <input type="radio" name="bd_" value="" /> <span>活动积温</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>常年积温</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>积温距平</span> </li>
                                            <li class="bd_item bd_item_3"> <input type="radio" name="bd_" value="" /> <span>阶段积温</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>累计降水距平</span> </li>
                                            <li class="bd_item bd_item_3 bd_item_m"> <input type="radio" name="bd_" value="" /> <span>连续无降水日</span> </li>
                                            <li class="bd_item bd_item_3"> <input type="radio" name="bd_" value="" /> <span>连续最长降水</span> </li>
                                        </ul>
                                    </div>
                                </div>`;

            _this.disPanel.insertAdjacentHTML("beforeEnd", thisView);
            _this.disBasicData = _this.disPanel.querySelector(".basic_data");
        },
        initSensitive: function( param ) {
            let _this = this,
                thisView = `<div class="sensitive_period">
                                <div class="sp_head">灾害敏感期</div>
                                <div class="sp_main">
                                    <div class="sp_progress">
                                        <div class="sp_p_line"></div>
                                    </div>
                                    <ul class="sp_disaster"></ul>
                                    <ul class="sp_growth"></ul>
                                </div>
                                <ul class="sp_legend">
                                    <li> <span class="period"></span> 当前生育期</li>
                                    <li> <span class="period_"></span> 生育期进程</li>
                                    <li> <span class="DT"></span> 干旱</li>
                                    <li> <span class="DH"></span> 干热风</li>
                                    <li> <span class="FD"></span> 霜冻害</li>
                                </ul>
                            </div>`;

            if ( param.type == "init" ) {
                _this.disPanel.insertAdjacentHTML("beforeEnd", thisView);
                _this.disSensitive = _this.disPanel.querySelector(".sensitive_period");
            }
            _this.sensitiveView({ area: "HHH", crop: "Winter wheat" });
        },
        sensitiveView: function( param ) {
            let _this = this,
                progres = _this.disSensitive.querySelector(".sp_p_line"),
                disaList = _this.disSensitive.querySelector(".sp_disaster"),
                growthList = _this.disSensitive.querySelector(".sp_growth"),
                currentGseason = _this.disFilter.querySelector("div[name='select'].gseason"),
                url = _this.disEventPath({ urlTypes: "sensitive" });

            RST.basic( url, "", function( result ) {
                let data = result.data,
                    gseasonH = currentGseason.querySelector("h"),
                    gseasonHV = gseasonH.getAttribute("value"),
                    _year = gseasonHV.split("~")[0], _num = 0;

                // 循环区域
                for ( let x = 0, len = data.length; x < len; x++ ) {
                    if ( data[x].value == param.area ) {
                        // 循环作物
                        let crops = data[x].crops;
                        for ( let y = 0, lenx = crops.length; y < lenx; y++ ) {
                            if ( crops[y].value == param.crop ) {
                                // 循环生育期
                                let disasterView = ``, growthView = ``, growths = crops[y].growthPeriod;

                                for ( let z = 0, leny = growths.length; z < leny; z++ ) {
                                    let cls = "", end = null, endTime = null,
                                        ctime = new Date().getTime(),
                                        start = _year+'-'+growths[z].startTime,
                                        startTime = new Date( start ).getTime();

                                    // 判断下一个生育期
                                    if ( growths[z+1] ) {
                                        end = _year+'-'+growths[z+1].startTime;
                                        endTime = new Date( end ).getTime();
                                        if ( _num > 0 ) {
                                            _year = Number( _year ) + 1;
                                            start = _year+'-'+growths[z].startTime;
                                            end = _year+'-'+growths[z+1].startTime;
                                            endTime = new Date( end ).getTime();
                                            _num = 0;
                                        }
                                        if ( endTime < startTime ) {
                                            end = (Number(_year)+1)+'-'+growths[z+1].startTime;
                                            _num += 1;
                                        }
                                    } else {
                                        end = _year+'-'+growths[0].startTime;
                                        endTime = new Date( end ).getTime();
                                    }

                                    if ( ctime < startTime ) cls = "undone";
                                    if ( ctime >= startTime && ctime < endTime ) cls = "default";

                                    growthView += `<li class="${ cls }" crop="${ param.crop }" title="${ start+"~"+end }">${ growths[z].name }</li>`;

                                    // 循环灾害
                                    let disasters = growths[z].disaster;
                                    for ( let l = 0, lenz = disasters.length; l < lenz; l++ ) {
                                        if ( disasters[l].isOccur ) {
                                            let style = `top: ${ z*25 }px; left: ${ l*12 }px;`;
                                            disasterView += `<li class="${ disasters[l].value }" title="${ disasters[l].name }" style="${ style }"></li>`;
                                        }
                                    }
                                    disaList.textContent = "";
                                    disaList.insertAdjacentHTML( "beforeEnd", disasterView );
                                }

                                growthList.textContent = "";
                                growthList.insertAdjacentHTML( "beforeEnd", growthView );
                                break;
                            }
                        }
                        break;
                    }
                }

                // 移动生育期
                if ( growthList.querySelector("li.default") ) {
                    growthList.querySelector("li.default")
                    .removeClass("default").addClass("undone")
                    .previousElementSibling.addClass("default");
                }

                // 更新进度及敏感期面板高度
                let itemList = growthList.querySelectorAll("li"),
                    itemSelect = growthList.querySelector("li.default") || itemList[ itemList.length - 1 ],
                    itemIndex = itemSelect.currentIndex();

                disaList.style.height = itemList.length * 25 +'px';
                progres.parentNode.style.height = itemList.length * 25 +'px';
                progres.style.height = ( itemIndex == ( itemList.length - 1 ) ) ? 'calc( 100% + 10px )' : itemIndex * 25 + 12 + 5 +'px';

                _this.sensitiveEvent( itemList );
            });
        },
        sensitiveEvent: function( list ) {
            let _this = this;

            for ( let x = 0, len = list.length; x < len; x++ ) {
                if ( !list[x].hasClass("undone") ) {
                    list[x].addEventListener( "click", function(e) {
                        let time = e.target.getAttribute("title").split("~");
                    
                        if ( list[x].hasClass("select") ) {
                            list[x].removeAllClass("select");

                            _this.triggerSearch({
                                type: "sensitive",
                                startTime: list[0].getAttribute("title").split("~")[0],
                                endTime: list[list.length-1].getAttribute("title").split("~")[1]
                            });
                        } else {
                            list[x].removeAllClass("select");
                            list[x].addClass("select");

                            _this.triggerSearch({
                                type: "sensitive",
                                startTime: time[0],
                                endTime: time[1]
                            });
                        }
                    }, false);
                }
            }
        },
        initDisList: function( param ) {
            let _this = this,
                thisView = `<div class="disaster_box">
                                    <ul class="ul_list"></ul>
                                </div>`;

            if ( param.type ) {
                if ( param.type == "init" ) {
                    _this.disPanel.insertAdjacentHTML("beforeEnd", thisView);
                    _this.disListBox = _this.disPanel.querySelector(".disaster_box");
                } else if ( param.type == "search" ) {
                    _this.disListView({ data: _this.disListData, condition: _this.disCondition });
                }
            }
        },
        disListView: function( param ) {
            let _this = this,
                disLists = _this.disListBox.querySelector(".ul_list");

            if ( param.data.status == 1 ) {
                let itemHtml = ``,
                    listData = param.data.data;

                for ( let x = 0; x < listData.length; x++ ) {
                    // 根据条件判断过滤
                    let starTime  = new Date( param.condition.starTime ).getTime(),
                        starTimex = new Date( listData[x].starTime ).getTime(),
                        endTime   = new Date( param.condition.endTime ).getTime(),
                        endTimex  = new Date( listData[x].endTime ).getTime();

                    if ( param.condition.area == "" && starTimex >= starTime && endTimex <= endTime ) {
                        if ( param.condition.keyWord != null ) {
                            if ( listData[x].text.indexOf( param.condition.keyWord ) > -1 ) {
                                itemHtml += _this.returnChildView( listData[x], x );
                            }
                        } else {
                            if ( listData[x].disaster_type == param.condition.disaster
                                && listData[x].category == param.condition.crop
                                && listData[x].disaster_area == param.condition.area
                            ) {
                                itemHtml += _this.returnChildView( listData[x], x );
                            } else if ( listData[x].disaster_type == param.condition.disaster_type
                                && listData[x].disaster_area == param.condition.area
                            ) {
                                itemHtml += _this.returnChildView( listData[x], x );
                            } else if ( listData[x].crop == param.condition.crop
                                && listData[x].disaster_area == param.condition.area
                            ) {
                                itemHtml += _this.returnChildView( listData[x], x );
                            } else if ( listData[x].disaster_type == param.condition.disaster
                                && listData[x].crop == param.condition.crop
                            ) {
                                itemHtml += _this.returnChildView( listData[x], x );
                            }
                        }
                    }

                    if ( !param.condition.keyWord && !param.condition.area
                        && !param.condition.crop && !param.condition.disaster
                    ) {
                        itemHtml += _this.returnChildView( listData[x], x );
                    }
                }

                disLists.textContent = "";
                _this.disListBox.scrollTop = 0;
                disLists.insertAdjacentHTML( 'beforeEnd', itemHtml );

                _this.disListEvent();
            } else {
                disLists.textContent = "";
                _this.disListBox.scrollTop = 0;
                disLists.insertAdjacentHTML( 'beforeEnd', `<p class="noData">暂无灾害事件</p>` );
            }
        },
        returnChildView: function( data, index ) {
            let _this = this,
                childView = ``;

            if ( data.detail ) {
                for ( let x = 0; x < data.detail.length; x++ ) {
                    let event = "",
                        thisText = "",
                        childData = data.detail[x];

                    thisText = childData.text;
                    if ( childData.status == 0 ) event = "noEvent";
                    if ( childData.type == "T0" ) thisText = formatTime( new Date(), "day" )+" "+childData.text;

                    // if ( childData.setting == 1 ) {
                        childView += `<li class="li_item ${ event }" type="${ childData.modelValue }"
                                    event="${ childData.status }" index="${ index+","+x }"> ${ childData.templateName } <span></span> 
                                    </li>`;
                    // } else {
                    //     childView += `<li class="li_item ${ event }" type="${ childData.modelValue }" index="${ index+","+x }"
                    //                 event="${ childData.status }"> ${ childData.templateName } </li>`;
                    // }
                }
            }

            let title = "",
                areaVal = data.areaAbbr,
                areaName = data.areaName,
                startDate = ( data.startDate ) ? data.startDate : "",
                endDate = ( data.endDate ) ? data.endDate : "",
                disType = data.disasterType,
                disName = data.disasterName,
                cropVal = data.cropName,
                cropName = data.cropNameCN,
                disStatus = ( data.disasterStatus === 1 ) ? "已完成" : "进行中";
            
            if ( data.disasterStatus === 1 ) {
                title = startDate +" ~ "+ endDate +" "+ areaName + cropName + disName;
            } else {
                title = startDate +" ~ - "+ areaName + cropName + disName;
            }

            let html =  `<li class="li_item" areaVal="${ areaVal }" cropVal="${ cropVal }" disType="${ disType }"
                            starTime="${ startDate }" endTime="${ endDate }" status="${ data.disasterStatus }">
                                <p class="item_text">${ title }</p>
                                <ul class="item_child_list"> ${ childView } </ul>
                                <p class="item_status">
                                    <span class="${ disType }">${ disName }</span>
                                    <span>${ disStatus }</span>
                                </p>
                            </li>`;

            return html;
        },
        disListEvent: function( param ) {
            let _this = this;
            
            let disItem = _this.disListBox.querySelectorAll(".ul_list > li"),
                disItemChild = _this.disListBox.querySelectorAll(".item_child_list > li"),
                disItemChildSpan = _this.disListBox.querySelectorAll(".item_child_list > li > span"),
                disSetting = document.querySelector(".disEvent_setting");

            // 父项
            function itemClick( e ) {
                let thisItem = e.target.parentNode;

                if ( thisItem.parentNode.hasClass("ul_list") ) {
                    removeAllClass( "select", disItemChildSpan );
                    removeAllClass( "select", disItemChild );
                    disSetting.hide();
                    _this.eventIndex = 0;

                    if ( thisItem.hasClass( "select" ) ) {
                        thisItem.removeAllClass("select");
                    } else {
                        thisItem.removeAllClass("select");
                        thisItem.addClass( "select" );
                    }
                }

                e.stopPropagation();
                return false;
            }

            for ( let x = 0; x < disItem.length; x++ ) {
                disItem[x].removeEventListener( 'click', itemClick, false);
                disItem[x].addEventListener( 'click', itemClick, false);
            }

            // 子项
            function itemChildClick( e ) {
                _this.eventIndex = 0;
                    
                if ( !e.target.hasClass("noEvent") && e.target.parentNode.hasClass("item_child_list") ) {
                    removeAllCommon();
                    MC.mapEvent.clearAllCover();
                    MC.mapEvent.closeAllLayer();
                    
                    // 初始化高级设置
                    _this.initDisSetView( e.target, disItemChildSpan, disSetting );
                    
                    // 初始化事件执行
                    if ( e.target.hasClass( "select" ) ) {
                        removeAllClass( "select", disItemChild );
                        removeAllClass( "select", disItemChildSpan );
                    } else {
                        removeAllClass( "select", disItemChild );
                        e.target.addClass( "select" );

                        // 移除灾害资料选项
                        let meteorEvent = document.querySelector(".meteor_list .meteor_child_item .item_set.select");
                        if ( meteorEvent ) meteorEvent.click();

                        e.target.querySelector("span").click();
                        removeAllClass( "select", disItemChildSpan );
                    
                        disSetting.hide();
                        if ( disSetting.querySelectorAll("li")[0] ) {
                            disSetting.querySelectorAll("li")[0].click();
                        }
                    }
                }

                e.stopPropagation();
                return false;
            }

            for ( let x = 0; x < disItemChild.length; x++ ) {
                disItemChild[x].removeEventListener( 'click', itemChildClick, false);
                disItemChild[x].addEventListener( 'click', itemChildClick, false);
            }
        },
        initDisSetView: function( itemChild, disItemChildSpan, disSetting ) {
            let _this = this;

            let status = 'init',
                extendView = `<h>背景资料</h>`,
                indexs = itemChild.getAttribute("index"),
                indexArry = indexs.split(","),
                level_one = _this.disListData.data[ indexArry[0] ].detail,
                level_two = level_one[ indexArry[1] ].detail.sort( objCompare( "order" ) );
                
            for ( let y = 0; y < level_two.length; y++ ) {
                let extendData = level_two[y];
                if ( y == _this.eventIndex ) {
                    extendView += `<li class="li_item select" element="${ extendData.element }" type="${ extendData.type }"
                                    indexs="${ indexs+","+y }" > ${ extendData.elementName } </li>`;
                } else {
                    extendView += `<li class="li_item" element="${ extendData.element }" type="${ extendData.type }"
                                    indexs="${ indexs+","+y }" > ${ extendData.elementName } </li>`;
                }
            }

            if (  disSetting.textContent != "" ) status = 'reset';
            disSetting.textContent = "";
            disSetting.insertAdjacentHTML("beforeEnd", extendView);
            let disSetItem = disSetting.querySelectorAll("li");

            // 高级
            _this.disListSetEvent({
                status: status,
                disSetting: disSetting,
                disSetItem: disSetItem,
                disItemChildSpan: disItemChildSpan
            });
        },
        disListSetEvent: function( param ) {
            let _this = this;

            // 高级选项按钮
            function itemChildSpanClick( e ) {
                if ( !e.target.parentNode.hasClass("noEvent")
                    && e.target.parentNode.hasClass( "select" )
                ) {
                    if ( e.target.hasClass( "select" ) ) {
                        removeAllClass( "select", param.disItemChildSpan );
                        param.disSetting.hide();
                    } else {
                        removeAllClass( "select", param.disItemChildSpan );
                        e.target.addClass( "select" );

                        param.disSetting.show(); 

                        let clientY = e.clientY, offsetY = e.offsetY,
                            centerY = e.clientY - e.offsetY + 15 - 50 - ( param.disSetting.clientHeight / 2 );
                        param.disSetting.style.top = centerY +"px";
                    }
                } else {
                    removeAllClass( "select", param.disItemChildSpan );
                    param.disSetting.hide();
                }

                e.stopPropagation();
                return false;
            }

            for ( let x = 0; x < param.disItemChildSpan.length; x++ ) {
                param.disItemChildSpan[x].removeEventListener( 'click', itemChildSpanClick, false);
                if ( param.status == 'init' ) param.disItemChildSpan[x].addEventListener( 'click', itemChildSpanClick, false);
            }
            
            // 高级选项子项
            function disSetItemClick( e ) {
                let event = e.target;
    
                if ( event.nodeName == "LI" ) {
                    removeAllCommon();
                    MC.mapEvent.clearAllCover();
                    MC.mapEvent.closeAllLayer();

                    if ( event.hasClass("select") ) {
                        event.removeAllClass( "select" );

                        let list = event.parentNode.querySelectorAll("li"),
                            indexs = list[0].getAttribute("indexs").split(",");
                            
                        _this.eventIndex = Number( indexs[ indexs.length - 1 ] );
                        _this.disListEventQuery({ indexs: indexs });
                    } else {
                        event.removeAllClass( "select" );
                        event.addClass( "select" );
    
                        let indexs = event.getAttribute("indexs").split(",");
                        _this.eventIndex = Number( indexs[ indexs.length - 1 ] );
                        _this.disListEventQuery({ indexs: indexs });
                    }
                }

                e.stopPropagation();
                return false;
            }


            for ( let x = 0; x < param.disSetItem.length; x++ ) {
                param.disSetItem[x].removeEventListener( 'click', disSetItemClick, false);
                param.disSetItem[x].addEventListener( 'click', disSetItemClick, false);
            }
        },
        disListEventQuery: function( param ) {
            let _this = this,
                eventOpt = _this.returnEventUrl( param );

            RST.basic( eventOpt.url, "", function( result ) {
                let contourParam = eventOpt.param,
                    types = eventOpt.param.urlTypes;

                if ( types == "weather,forecast" ) {
                    let items = [];

                    for ( let x = 0; x < result.data.length; x++ ) {
                        items.push({ value: result.data[x].actualDate });
                    }
                    
                    TimeLine.validMain.init({
                        type: "customx",
                        customItems: items,
                        elmt: document.querySelector(".main")
                    });

                    contourParam.urlTypes = types+",contour";
                    let contourImage = encodeURI( _this.disEventPath( contourParam ) );
                    
                    RST.ContourImage( contourImage, "", function( resultx ) {
                        _this.timeLineClick({
                            data: result.data,
                            datax: resultx.data,
                            param: eventOpt
                        });

                        MC.mapEvent.drawChromatic( result.data[0], { opacity: 1 } );

                        if ( resultx.status === 1 ) {
                            for ( let x = 0; x < resultx.data.length; x++ ) {
                                if ( resultx.data[x].actualDate == result.data[0].actualDate ) {
                                    MC.mapEvent.drawImageLayer( resultx.data[x], { title: false, opacity: 1 } );
                                    break;
                                }
                                if ( y == param.datax.length - 1 ) Popup.tipPopup({ type: "toast", content: `当前等值线无数据！` });
                            }
                        } else {
                            Popup.tipPopup({ type: "toast", content: `当前等值线无数据！` });
                        }
                    });
                } else if ( types == "weather,observe" ) {
                    let timeLen = 15 * 24 * 60 * 60 * 1000,
                        start = new Date( eventOpt.param.startDate ).getTime(),
                        end = new Date( eventOpt.param.endDate ).getTime();

                    if ( ( end - start ) > timeLen ) {
                        start = formatTime( new Date( eventOpt.param.endDate ), "day", -(timeLen) );
                    } else {
                        start = eventOpt.param.startDate;
                    }

                    TimeLine.validMain.init({
                        type: "custom",
                        startTime: start,
                        endTime: eventOpt.param.endDate,
                        elmt: document.querySelector(".main")
                    });

                    contourParam.urlTypes = types+",contour";
                    let contourImage = encodeURI( _this.disEventPath( contourParam ) );

                    RST.ContourImage( contourImage, "", function( resultx ) {
                        _this.timeLineClick({
                            data: result.data,
                            param: eventOpt,
                            contour: contourImage
                        });

                        MC.mapEvent.drawChromatic( result.data[ result.data.length - 1 ], { opacity: 1 } );

                        if ( resultx.status === 1 ) {
                            MC.mapEvent.drawImageLayer( resultx.data, { title: false, opacity: 1 } );
                        } else {
                            Popup.tipPopup({ type: "toast", content: `当前等值线无数据！` });
                        }
                    });
                } else if ( types == "crop,growth" || types == "crop,distribution" || types == "crop,loss" ) {
                    let vtJson = result.data.detail.replace(/<\/?.+?>/g,"").replace(/[\r\n]/g, ""),
                        data = JSON.parse( vtJson ), colorType = eventOpt.param.disType;

                    if ( result.data ) {
                        if ( types == "crop,distribution" ) colorType = "cropDistribution";
                        if ( types == "crop,loss" ) colorType = "cropLoss";
                        gridHeatMap.initGrid( data[0], colorType );
                    } else {
                        Popup.tipPopup({ type: "toast", content: "当前无数据！" });
                    }
                } else if ( types == "disaster,distribution" ) {
                    if ( eventOpt.param.disModel != "T2" && eventOpt.param.disModel != "T3" ) {
                        let timeLen = 15 * 24 * 60 * 60 * 1000,
                            start = new Date( eventOpt.param.startDate ).getTime(),
                            end = new Date( eventOpt.param.endDate ).getTime();

                        if ( ( end - start ) > timeLen ) {
                            start = formatTime( new Date( eventOpt.param.endDate ), "day", -(timeLen) );
                        } else {
                            start = eventOpt.param.startDate;
                        }

                        TimeLine.validMain.init({
                            type: "custom",
                            startTime: start,
                            endTime: eventOpt.param.endDate,
                            elmt: document.querySelector(".main")
                        });

                        _this.timeLineClick({ param: eventOpt });
                    }

                    if ( result.data ) {
                        let vtJson = result.data.detail.replace(/<\/?.+?>/g,"").replace(/[\r\n]/g, ""),
                            data = JSON.parse( vtJson );

                        gridHeatMap.initGrid( data[0], eventOpt.param.disType );
                    } else {
                        Popup.tipPopup({ type: "toast", content: "当前无数据！" });
                    }
                } else if ( types == "crop,NDVI" ) {
                    TimeLine.validMain.init({
                        type: "custom",
                        startTime: eventOpt.param.startDate,
                        endTime: eventOpt.param.endDate,
                        elmt: document.querySelector(".main")
                    });

                    _this.timeLineClick({ param: eventOpt });

                    if ( result ) {
                        gridHeatMap.initGrid( result[0], "NDVI" );
                    } else {
                        Popup.tipPopup({ type: "toast", content: "当前无数据！" });
                    }
                }

                if ( !result.data ) return false;
                if ( eventOpt.param.disModel == "T0" ) return false;

                let typeArry = [ "disaster,distribution", "crop,loss" ];
                if ( !typeArry.includes( types ) ) return false;

                result = null;

                rightPanel.init({
                    type: "area",
                    panelType: "disaster",
                    disCrop: eventOpt.param.disCrop,
                    disType: eventOpt.param.disType,
                    disEvent: eventOpt.param.disEvent,
                    disArea: eventOpt.param.disArea,
                    disModel: eventOpt.param.disModel,
                    disDate: eventOpt.param.endDate,
                    lngLat: []
                });
            });
        },
        timeLineClick: function( param ) {
            let _this = this,
                eventOpt = param.param,
                lineItem = document.querySelectorAll(".timeLine .line_item");

            for ( let x = 0; x < lineItem.length; x++ ) {
                lineItem[x].addEventListener( "click", function(e) {
                    MC.mapEvent.closeAllLayer();
                    let currentTime = lineItem[x].getAttribute("time");

                    if ( eventOpt.param.urlTypes == "weather,forecast"
                        || eventOpt.param.urlTypes == "weather,forecast,contour"
                    ) {
                        MC.mapEvent.drawChromatic( param.data[x], { opacity: 1 } );
                        for ( let y = 0; y < param.datax.length; y++ ) {
                            if ( param.datax[y].actualDate == param.data[x].actualDate ) {
                                MC.mapEvent.drawImageLayer( param.datax[y], { title: false, opacity: 1 } );
                                break;
                            }
                            if ( y == param.datax.length - 1 ) Popup.tipPopup({ type: "toast", content: `当前等值线无数据！` });
                        }
                    } else if ( eventOpt.param.urlTypes == "weather,observe"
                        || eventOpt.param.urlTypes == "weather,observe,contour"
                    ) {
                        let prevUrl = param.contour.split("&"), currentUrl = prevUrl[0];
                        for ( let y = 1; y < prevUrl.length; y++ ) {
                            if ( prevUrl[y].indexOf("observeDate=") > -1 ) prevUrl[y] = "observeDate="+currentTime;
                            currentUrl += "&"+prevUrl[y];
                        }

                        MC.mapEvent.drawChromatic( param.data[x], { opacity: 1 } );

                        RST.ContourImage( currentUrl, "", function( resultx ) {
                            if ( resultx.status === 1 ) {
                                MC.mapEvent.drawImageLayer( resultx.data, { title: false, opacity: 1 } );
                            } else {
                                Popup.tipPopup({ type: "toast", content: `当前等值线无数据！` });
                            }
                        });
                    } else if ( eventOpt.param.urlTypes == "crop,growth"
                        || eventOpt.param.urlTypes == "crop,distribution"
                        || eventOpt.param.urlTypes == "crop,loss"
                        || eventOpt.param.urlTypes == "disaster,distribution"
                    ) {
                        let prevUrl = param.param.url.split("&"), currentUrl = prevUrl[0];
                        for ( let y = 1; y < prevUrl.length; y++ ) {
                            if ( prevUrl[y].indexOf("distributeDate=") > -1 ) {
                                prevUrl[y] = "distributeDate="+currentTime;
                            } else if ( prevUrl[y].indexOf("resultDate=") > -1 ) {
                                prevUrl[y] = "resultDate="+currentTime;
                            }
                            currentUrl += "&"+prevUrl[y];
                        }

                        RST.basic( currentUrl, "", function( result ) {
                            if ( result.data ) {
                                let vtJson = result.data.detail.replace(/<\/?.+?>/g,"").replace(/[\r\n]/g, ""),
                                    data = JSON.parse( vtJson );
                                gridHeatMap.initGrid( data[0], eventOpt.param.disType );

                                if ( eventOpt.param.disModel == "T0" ) return false;
                                if ( eventOpt.param.urlTypes != "disaster,distribution" ) return false;

                                rightPanel.init({
                                    type: "area",
                                    panelType: "disaster",
                                    disCrop: eventOpt.param.disCrop,
                                    disType: eventOpt.param.disType,
                                    disEvent: eventOpt.param.disEvent,
                                    disArea: eventOpt.param.disArea,
                                    disModel: eventOpt.param.disModel,
                                    disDate: eventOpt.param.endDate,
                                    lngLat: []
                                });
                            } else {
                                Popup.tipPopup({ type: "toast", content: "当前无数据！" });
                            }
                            result = null;
                        });
                    } else if ( eventOpt.param.urlTypes == "crop,NDVI" ) {
                        let oldUrl = param.param.url.split("NDVI/"),
                            oldFileName = oldUrl[1].split("_"),
                            currentUrl = oldUrl[0] + "NDVI/";

                        for ( let z = 0; z < oldFileName.length; z++ ) {
                            if ( z == 0 ) {
                                oldFileName[z] = formatTime( currentTime, 'day_' );
                                currentUrl += oldFileName[z];
                            } else {
                                currentUrl += ( "_"+ oldFileName[z] );
                            }
                        }

                        RST.basic( currentUrl, "", function( result ) {
                            if ( result ) {
                                gridHeatMap.initGrid( result[0], "NDVI" );
                            } else {
                                Popup.tipPopup({ type: "toast", content: "当前无数据！" });
                            }
                            result = null;
                        });
                    }

                    lineItem[x].removeAllClass("select");
                    lineItem[x].addClass("select");
                }, false);
            }

            if ( eventOpt.param.urlTypes == "weather,forecast"
                || eventOpt.param.urlTypes == "weather,forecast,contour"
            ) {
                lineItem[0].addClass("select");
            } else {
                lineItem[ lineItem.length - 1 ].addClass("select");
            }
        },
        returnEventUrl: function( param ) {
            let _this = this,
                thisParam = _this.returnItemParam( param );

            if ( param.currentTime ) thisParam["currentTime"] = param.currentTime;
            thisParam["urlTypes"] = thisParam.disGroup +","+ thisParam.disItemType;

            let urlPath = encodeURI( _this.disEventPath( thisParam ) );

            return {
                url: urlPath,
                param: thisParam
            };
        },
        returnItemParam: function( param ) {
            let _this = this,
                thisParam = {},
                level_1 = _this.disListData.data[ param.indexs[0] ],
                level_2 = level_1.detail[ param.indexs[1] ],
                level_3 = level_2.detail[ param.indexs[2] ];

            thisParam["disArea"]   = level_1.areaAbbr;
            thisParam["disCrop"]   = level_1.cropName;
            thisParam["disEvent"]  = level_1.eventId;
            thisParam["disType"]   = level_1.disasterType;
            thisParam["disModel"]  = level_2.modelValue;
            thisParam["disItemType"] = level_3.type;
            thisParam["disGroup"]  = level_3.group;
            thisParam["disElmt"]   = level_3.element;
            thisParam["startDate"] = level_1.startDate;
            thisParam["endDate"]   = level_1.endDate || formatTime("", "day");
            thisParam["oneDay"]    = 24 * 60 * 60 * 1000;

            return thisParam;
        },
        disEventPath: function( param ) {
            let _this = this,
                pathHead = "",
                pathCont = "",
                currentPath = "";

            switch( param.urlTypes ) {
                case "condition": // 获取灾害条件
                    currentPath = Path + "/data/basic/filiter.json";
                break;
                case "sensitive": // 获取灾害敏感期
                    currentPath = Path + "/data/basic/sensitivePeriod.json";
                    // currentPath = "http://103.254.67.177:8030/medwas_data/crop/getGrowthPeriod?growthArea=HHH&cropName=Winter%20wheat&growthYear=2018~2019"
                break;
                case "search": // 获取灾害列表
                    pathHead = NetWorkPath + "/disaster/getDisasterEvent?";
                    currentPath = pathHead + pathCont;
                break;
                case "weather,forecast": // 获取预报格点
                    pathHead = NetWorkPath + "/weather/getForecastGridDataOfModel?";
                    pathCont = "position=1&group="+ param.disGroup +"&type="+ param.disItemType
                                +"&forecastArea="+ param.disArea +"&cropName="+ param.disCrop
                                +"&modelValue=T0&disasterType="+ param.disType +"&elementValue="+ param.disElmt
                                +"&fileType=json&fileLevel=0&forecastDate="+ param.endDate;
                    currentPath = pathHead + pathCont;
                break;
                case "weather,forecast,contour":
                    pathHead = NetWorkPath + "/weather/getForecastGridData?";
                    pathCont = "forecastArea="+ param.disArea +"&elementValue="+ param.disElmt
                                +"&fileType=contour_png&fileLevel=0&forecastLevel=0"
                                +"&forecastDate="+ param.endDate;
                    currentPath = pathHead + pathCont;
                break;
                case "weather,observe": // 获取实况格点
                    pathHead = NetWorkPath + "/weather/getObserveGridDataByRangeDate?";
                    pathCont = "observeArea="+ param.disArea +"&elementValue="+ param.disElmt
                                +"&startDate="+ param.startDate +"&endDate="+ param.endDate
                                +"&observeHour=24&fileType=json&fileLevel=0";
                    currentPath = pathHead + pathCont;
                break;
                case "weather,observe,contour":
                    pathHead = NetWorkPath + "/weather/getObserveGridData?";
                    pathCont = "observeArea="+ param.disArea +"&elementValue="+ param.disElmt
                                +"&fileType=contour_png&fileLevel=0"
                                +"&observeDate="+ param.endDate +"&observeHour=24";
                    currentPath = pathHead + pathCont;
                break;
                case "crop,growth": // 获取作物生育期
                    pathHead = NetWorkPath + "/crop/getCropGrowthOfModel?";
                    currentPath = pathHead + pathCont;
                break;
                case "crop,distribution": // 获取作物分布
                    // pathHead = NetWorkPath + "/crop/getCropDistributionOfModel?";
                    // pathCont = "position=2&group="+ param.disGroup +"&type="+ param.disItemType
                    //             +"&distributeArea="+ param.disArea +"&cropName="+ param.disCrop 
                    //             +"&modelValue="+ param.disModel +"&disasterType="+ param.disType +"&distributeDate="+ param.startDate
                    //             +"&fileType=json";
                    // currentPath = pathHead + pathCont;
                    pathHead = NetWorkPath + "/crop/getCropDistribution?";
                    pathCont = "cropArea="+ param.disArea +"&cropName="+ param.disCrop
                                +"&fileType=json&fileLevel=0";
                    currentPath = pathHead + pathCont;
                break;
                case "device,distribution":
                    pathHead = NetWorkPath + "/crop/getWeatherDeviceByAreaName?";
                    pathCont = "areaName="+ param.disArea;
                    currentPath = pathHead + pathCont;
                break;
                case "crop,NDVI": // 获取作物NDVI
                    // pathHead = NetWorkPath + "/crop/getCropProductByRangeDate?";
                    // pathCont = "position=2&group="+ param.disGroup +"&type="+ param.disItemType
                    //             +"&distributeArea="+ param.disArea +"&cropName="+ param.disCrop 
                    //             +"&modelValue="+ param.disModel +"&disasterType="+ param.disType +"&distributeDate="+ param.startDate
                    //             +"&fileType=json";
                    // pathCont = "position=2&group="+ param.disGroup +"&type="+ param.disItemType +"&productArea="+ param.disArea
                    //             +"&cropName="+ param.disCrop +"&modelValue="+ param.disModel +"&disasterType="+ param.disType
                    //             +"&startDate="+ param.startDate +"&endDate="+ param.endDate
                    //             +"&productType="+ param.disItemType +"&productVersion=json";
                    // currentPath = pathHead + pathCont;
                    currentPath = "../simulation/NDVI/"+ formatTime( param.endDate, 'day_' ) +"_HHH_NDVI.json";
                break;
                case "crop,NDVI": // 获取历史平均NDVI
                    // pathHead = NetWorkPath + "/model/getModelResult?";
                    // pathCont = "";
                    // currentPath = pathHead + pathCont;
                    currentPath = "../simulation/NDVI/"+ formatTime( param.endDate, 'day_' ) +"_HHH_NDVI.json";
                break;
                case "crop,loss": // 获取灾害损失率
                    pathHead = NetWorkPath + "/model/getModelResultByEventId?";
                    pathCont = "position=2&group="+ param.disGroup +"&type="+ param.disItemType
                                +"&modelArea="+ param.disArea +"&cropName="+ param.disCrop
                                +"&eventId="+ param.disEvent +"&modelValue="+ param.disModel +"&disasterType="+ param.disType
                                +"&fileType=json&fileLevel=0";
                    currentPath = pathHead + pathCont;
                break;
                case "disaster,distribution": // 获取灾害分布
                    if ( param.disModel == "T2" ) {
                        pathHead = NetWorkPath + "/model/getModelResultByEventId?";
                        pathCont = "position=2&group="+ param.disGroup +"&type="+ param.disItemType
                                    +"&modelArea="+ param.disArea +"&cropName="+ param.disCrop
                                    +"&eventId="+ param.disEvent +"&modelValue="+ param.disModel +"&disasterType="+ param.disType
                                    +"&fileType=json&fileLevel=0";
                    } else {
                        pathHead = NetWorkPath + "/model/getModelResult?";
                        pathCont = "group="+ param.disGroup +"&type=result"
                                    +"&modelArea="+ param.disArea +"&cropName="+ param.disCrop
                                    +"&modelValue="+ param.disModel +"&disasterType="+ param.disType +"&resultDate="+ param.endDate
                                    +"&fileType=json&fileLevel=0"
                    }
                    currentPath = pathHead + pathCont;
                break;
            }

            return currentPath;
        }
    };

    disEventPanel.initView();

    // 移除所有通用
    function removeAllCommon() {        
        // 隐藏高级设置
        let disEvent = document.querySelector(".disaster_box .item_child_list span.select");
        if ( disEvent ) disEvent.click();

        // 移除右侧弹窗
        let rightPanel = document.querySelector(".rightPanel");
        if ( rightPanel ) rightPanel.remove();

        // 移除时间轴
        let timeLine = document.querySelector(".timeLine");
        if ( timeLine ) timeLine.remove();

        // 移除图例
        let legend = document.querySelector(".legend");
        if ( legend ) legend.remove();

        // 移除标题
        let title = document.querySelector(".title");
        if ( title ) title.remove();
    }
});